<script setup>
	import FirstTitle from "@comp/FirstTitle";
	import {
		Editor,
		Toolbar
	} from "@wangeditor/editor-for-vue";
	import {
		onMounted
	} from "vue";
	
	import {
		searchDataZhbz
	} from "@/api/search";
	import {
		addOrUpdateZhbz
	} from "@/api/addOrUpdate";
	
	import { postTableData } from "@/api/table";


	const city = window.globalObj.name;


	const editorRef = shallowRef();
	const editorRef1 = shallowRef();
	const editorRef2 = shallowRef();
	const toolbarConfig = {};
	const toolbarConfig1 = {};
	const toolbarConfig2 = {};
	const editorConfig = {
		placeholder: "请输入内容..."
	};
	const mode = ref("default");
	const mode1 = ref("default");
	const mode2 = ref("default");
	
	// 加载html
	const initHtml = () => {
		return searchDataZhbz({
			m: "能力现状-物资经费保障能力现状"
		}).then((res) => {
			const {
				data
			} = res
			valueHtml.value = data.find((x) => x.k === "生活物资战储情况")?.v || "";
			valueHtml1.value = data.find((x) => x.k === "生活物资市场供应情况统计")?.v || "";
			valueHtml2.value = data.find((x) => x.k === "救灾物资战储情况")?.v || "";
		})
	};
	
	
	const handleCreated = (editor) => {
		editorRef.value = editor; // 记录 editor 实例，重要！
	};
	const handleCreated1 = (editor) => {
		editorRef1.value = editor; // 记录 editor 实例，重要！
	};
	const handleCreated2 = (editor) => {
		editorRef2.value = editor; // 记录 editor 实例，重要！
	};
	
	
	const valueHtml = ref(
		"米、面生活必需品约XX万kg，可保障辖区内XX万人、XX天的基本生活。具体情况如下："
	);
	const valueHtml1 = ref(
		"米、面生活必需品约XX万kg，可保障辖区内XX万人、XX天的基本生活。具体情况如下："
	)
	const valueHtml2 = ref(
		"米、面生活必需品约XX万kg，可保障辖区内XX万人、XX天的基本生活。具体情况如下："
	)
	
	
	const saveProgramme = () => {
		ElMessageBox.confirm(`确定要保存吗?`, "警告", {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
			customClass: "message-box",
		}).then(() => {
			addOrUpdateZhbz({
					m: "能力现状-物资经费保障能力现状",
					data: [{
							k: "生活物资战储情况",
							v: valueHtml.value,
						},
						{
							k: "生活物资市场供应情况统计",
							v: valueHtml1.value,
						},
						{
							k: "救灾物资战储情况",
							v: valueHtml2.value,
						}
					],
				})
				.then((result) => {
					if (result.code === 200) {
						ElMessage.success("操作成功");
						initHtml();
					} else {
						ElMessage.error(result.msg);
					}
				})
				.catch(() => {});
		});
	}
	
	
	onBeforeUnmount(() => {
	
		const editor = editorRef.value;
		const editor1 = editorRef1.value;
		const editor2 = editorRef2.value;
		if (!editor) return;
		if (!editor1) return;
		if (!editor2) return;
		editor.destroy();
		editor1.destroy();
		editor2.destroy();
	});

	// 表头单元格样式
	const headerCellStyle = () => {
		return {
			backgroundColor: "#f5f7fa",
			color: "rgba(0,0,0,0.85)",
			fontSize: "14px",
			height: "54px",
		};
	};
	// 单元格样式
	const cellStyle = () => {
		return {
			color: "rgba(0,0,0,0.65)",
			fontSize: "14px",
			lineHeight: "22px",
		};
	};

	const tableData1 = ref([])
	const tableData2 = ref([])
	const tableData3 = ref([])
	const getList1 = () => {
		return postTableData({
			docType: "comprehensiveSupport",
			method: "shenghuowuzizhanchuqingkuang",
		}).then(result=>{
			if(result.code === 200){
				tableData1.value = result?.data || []
			}
		})
	}
	const getList3 = () => {
		return postTableData({
			docType: "comprehensiveSupport",
			method: "shenghuowuzishichanggongyingqingkuang",
		}).then(result=>{
			if(result.code === 200){
				tableData2.value = result?.data || []
			}
		})
	}
	const getList2 = () => {
		return postTableData({
			docType: "comprehensiveSupport",
			method: "jiuzaiwuziqingkuang",
		}).then(result=>{
			if(result.code === 200){
				tableData3.value = result?.data || []
			}
		})
	}
	onMounted(async () => {
		await initHtml()
		await getList1()
		await getList2()
		await getList3()
	});
</script>
<template>
	<div class="">
		<FirstTitle name="生活物资战储情况" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig"
				:mode="mode" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml" :defaultConfig="editorConfig"
				:mode="mode" @onCreated="handleCreated" />
		</div>
		
		<!-- <div class="top-15">
			
		</div> -->
		<!-- <div class="top-15 text-center">
			{{city}}生活物资战储情况统计表（单位:万kg）
		</div>
		<el-table id="table" :data="tableData1" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border >
			<el-table-column prop="rowNum" label="序号" width="100" align="center" />
			<el-table-column prop="jd_name" label="行政区划" />
			<el-table-column prop="wz_name" label="物资" />
			<el-table-column prop="standard" label="标准" />
			<el-table-column prop="measuring_unit" label="计量单位" />
			<el-table-column prop="storage_sum" label="数量" />
			<el-table-column prop="note" label="说明" />
		</el-table> -->
		
		<FirstTitle name="生活物资市场供应情况统计" class="top-15" />
		<!-- <div class="top-15">
			
		</div> -->
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef1" :defaultConfig="toolbarConfig1"
				:mode="mode1" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml1" :defaultConfig="editorConfig"
				:mode="mode1" @onCreated="handleCreated1" />
		</div>
		
		
		<!-- <div class="top-15 text-center">
			{{city}}生活物资市场供应情况统计（单位:万kg）
		</div>
		<el-table id="table" :data="tableData2" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border >
			<el-table-column prop="rowNum" label="序号" width="100" align="center" />
			<el-table-column prop="jd_name" label="行政区划" />
			<el-table-column prop="wz_name" label="物资" />
			<el-table-column prop="measuring_unit" label="计量单位" />
			<el-table-column prop="storage_sum" label="数量" />
			<el-table-column prop="remark" label="说明" />
		</el-table> -->
		
		
		<FirstTitle name="救灾物资战储情况" class="top-15" />
		<!-- <div class="top-15">
			共储备帐篷XX顶、折叠床XX张、成套的棉被等物品XX套，可保障XX人临时宿营。具体情况如下：
		</div> -->
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef2" :defaultConfig="toolbarConfig2"
				:mode="mode2" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml2" :defaultConfig="editorConfig"
				:mode="mode2" @onCreated="handleCreated2" />
		</div>
		
		
		
		<!-- <div class="top-15 text-center">
			{{city}}救灾物资情况统计表
		</div>
		<el-table id="table" :data="tableData3" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border >
			<el-table-column prop="rowNum" label="序号" width="100" align="center" />
			<el-table-column prop="jd_name" label="行政区划" />
			<el-table-column prop="equ_name" label="物资" />
			<el-table-column prop="standard" label="标准" />
			<el-table-column prop="unit" label="计量单位" />
			<el-table-column prop="number" label="数量" />
			<el-table-column prop="remark" label="说明" />
		</el-table> -->
		
		<!-- <FirstTitle name="经费保障现状" class="top-15" />
		<div class="top-15">
			辖区内XX万人、可使用经费XX亿元。
		</div> -->
		
	




		<div class="flex-justify-end top-20">
			<el-button type="primary" class="save-btn" @click="saveProgramme">保存</el-button>
		</div>
	</div>
</template>
<style scoped lang="scss"></style>